package com.ash.controller;

import com.ash.configuration.MyApp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: Ashin
 * @Date: 2021/5/11
 * @Description: com.ashin.controller
 * @Version: 1.0.0
 */
@RestController
public class HelloController {

    @Autowired
    private MyApp myApp;

    @Value("${name}")
    private List<String> names;

    @Autowired
    private ConfigurableApplicationContext context;

    @GetMapping("/")
    public MyApp home() {
        System.out.println(names);

        Map<String, Object> systemEnvironment = context.getEnvironment().getSystemEnvironment();
        System.out.println(systemEnvironment);
        System.out.println("=======");
        Map<String, Object> systemProperties = context.getEnvironment().getSystemProperties();
        System.out.println(systemProperties);
        System.out.println("=======");
        MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
        System.out.println(propertySources);
        System.out.println("=======");
        System.out.println(context.getEnvironment().getProperty("name"));
        System.out.println(context.getEnvironment().getProperty("sun.jnu.encoding"));
        System.out.println(context.getEnvironment().getProperty("zhouyu"));

        return myApp;
    }
}
